<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>7.1</title>
    <style>
        .box {
            margin: 140px auto;
            width: 240px;
            border: 1px rebeccapurple solid;
        }

        button {
            margin: 5px;
        }
    </style>
</head>

<body>
    <div class="box">
        <button>按钮</button>
        <button>按钮</button>
        <button>按钮</button>
        <button>按钮</button>

    </div>
    <script>
        var bts = document.querySelector('.box').querySelectorAll('button');
        console.log(bts);
        for (let index = 0; index < bts.length; index++) {
            bts[index].onclick = function () {
                for (let index = 0; index < bts.length; index++) {
                    bts[index].style.backgroundColor='';
                    
                }
               bts[index].style.backgroundColor='#bfa';
            }
        }
    </script>


</body>

</html>